package main

import "fmt"

type Element interface{} // Element为接口别名
type List []Element      // list[]调换为接口别名

type Person struct { // 定义结构体 Person
	name string
	age  int
}

func (p Person) String() string {
	return "name is" + p.name + ".age is" + string(p.age)
}

func main() {
	list := make(List, 3)
	list[0] = 1
	list[1] = "Hello"
	list[2] = Person{"Dennis", 70}

	for index, element := range list {
		if value, ok := element.(string); ok {
			fmt.Println("value", value)
			fmt.Println("ok", ok)
		}

		switch value := element.(type) {
		case int:
			fmt.Println("int类型", index, value)
		case string:
			fmt.Println("string类型", index, value)
		case Person:
			fmt.Println("Person类型", index, value)
		default:
			fmt.Println("未知类型", index, value)
		}
	}
}
